package com.mav.controller;

import com.mav.mapper.ClazzMapper;
import com.mav.pojo.Clazz;
import com.mav.pojo.ClazzQueryParam;
import com.mav.pojo.PageResult;
import com.mav.pojo.Result;
import com.mav.service.ClazzService;
import com.mav.service.iml.DeleteException;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RequestMapping("/clazzs")
@RestController
@Slf4j
public class ClazzController {
    @Autowired
    ClazzService clazzService;
    @GetMapping("/list")
    public Result findAllClazz(){
        List<Clazz> list= clazzService.findAllClazz();
        return Result.success(list);
    }
    @GetMapping
    public Result page(ClazzQueryParam clazzQueryParam) {
        log.info("页面请求参数:{}",clazzQueryParam);
        PageResult<Clazz> pageResult=clazzService.page(clazzQueryParam);
        return Result.success(pageResult);
    }
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id) throws DeleteException {
        log.info("要删除班级的id:{}",id);
        clazzService.deleteById(id);
        return Result.success();
    }
    @PostMapping
    public Result add(@RequestBody Clazz clazz){
        log.info("要添加的班级:{}",clazz);
        clazzService.add(clazz);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        log.info("要删除的班级的id:{}",id);
        Clazz clazz=clazzService.getById(id);
        return Result.success(clazz);
    }
    @PutMapping
    public Result update(@RequestBody Clazz clazz){
        log.info("班级修改数据:{}",clazz);
        clazzService.update(clazz);
        return Result.success();
    }


}
